package com.qingcheng.dao;

import com.qingcheng.pojo.system.Menu;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

public interface MenuMapper extends Mapper<Menu> {


    @Select("SELECT id,name,icon,url,parent_id As parentId FROM tb_menu WHERE id IN(" +
            "\tSELECT parent_id FROM tb_menu WHERE id IN(" +
            "\t\tSELECT parent_id FROM tb_menu WHERE id IN(" +
            "\t\t\tSELECT menu_id FROM tb_resource_menu WHERE resource_id IN(" +
            "\t\t\t\tSELECT id FROM tb_resource WHERE id IN (" +
            "\t\t\t\t\tSELECT resource_id from tb_role_resource WHERE role_id IN(" +
            "\t\t\t\t\t\tSELECT role_id from tb_admin_role WHERE admin_id IN (" +
            "\t\t\t\t\t\t\tSELECT id from tb_admin WHERE login_name=#{loginName}" +
            "\t\t\t\t\t\t)" +
            "\t\t\t\t\t)" +
            "\t\t\t\t)" +
            "\t\t\t)" +
            "\t\t)" +
            "\t)" +
            ")" +
            " UNION " +
            "SELECT id,name,icon,url,parent_id As parentId FROM tb_menu WHERE id IN(" +
            "\tSELECT parent_id FROM tb_menu WHERE id IN(" +
            "\t\tSELECT menu_id FROM tb_resource_menu WHERE resource_id IN(" +
            "\t\t\tSELECT id FROM tb_resource WHERE id IN (" +
            "\t\t\t\tSELECT resource_id from tb_role_resource WHERE role_id IN(" +
            "\t\t\t\t\tSELECT role_id from tb_admin_role WHERE admin_id IN (" +
            "\t\t\t\t\t\tSELECT id from tb_admin WHERE login_name=#{loginName}" +
            "\t\t\t\t\t)" +
            "\t\t\t\t)" +
            "\t\t\t)" +
            "\t\t)" +
            "\t)" +
            ")" +
            " UNION " +
            "SELECT id,name,icon,url,parent_id As parentId FROM tb_menu WHERE id IN(" +
            "\tSELECT menu_id FROM tb_resource_menu WHERE resource_id IN(" +
            "\t\tSELECT id FROM tb_resource WHERE id IN (" +
            "\t\t\tSELECT resource_id from tb_role_resource WHERE role_id IN(" +
            "\t\t\t\tSELECT role_id from tb_admin_role WHERE admin_id IN (" +
            "\t\t\t\t\tSELECT id from tb_admin WHERE login_name=#{loginName}" +
            "\t\t\t\t)" +
            "\t\t\t)" +
            "\t\t)" +
            "\t)" +
            ")")
    public List<Menu> findMenuByLoginName(@Param("loginName") String loginName);

}
